Improving handling of tooltip-text property. Also check result of tooltip
authorMathias Hasselmann <mathias.hasselmann@gmx.de>
Fri, 15 Jun 2007 18:25:11 +0000 (18:25 +0000)
committerMathias Hasselmann <hasselmm@src.gnome.org>
Fri, 15 Jun 2007 18:25:11 +0000 (18:25 +0000)
2007-06-15 Mathias Hasselmann <mathias.hasselmann@gmx.de>

* gtk/gtkwidget.c: Improving handling of tooltip-text property.
* tests/testtooltips.c: Also check result of tooltip getters.

svn path=/trunk/; revision=18143

ChangeLog
gtk/gtkwidget.c
tests/testtooltips.c

index 76bc929cb24602cc6127f0284c8c8f0457454c16..d95cf21f36abc4cabf612fab05db5d5a6f771500 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-15  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
+
+       * gtk/gtkwidget.c: Improving handling of tooltip-text property.
+       * tests/testtooltips.c: Also check result of tooltip getters.
+
 2007-06-15  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
 
        * docs/reference/gtk/gtk-sections.txt, gtk/gtk.symbols,
index 97c242f854c09ba01f07ceb41e6b9335e913226d..577b1dbc02392f1aa884b8956f29b5426672e6b4 100644 (file)
@@ -2042,8 +2042,7 @@ gtk_widget_set_property (GObject         *object,
       g_object_set_qdata_full (object, quark_tooltip_markup,
                                tooltip_markup, g_free);
 
-      tmp = (tooltip_window != NULL || tooltip_markup != NULL);
-      gtk_widget_set_has_tooltip (widget, tmp, FALSE);
+      gtk_widget_set_has_tooltip (widget, TRUE, FALSE);
       break;
     default:
       break;
@@ -2145,20 +2144,12 @@ gtk_widget_get_property (GObject         *object,
     case PROP_TOOLTIP_TEXT:
       {
         gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
-        if (!escaped)
-          g_value_set_string (value, NULL);
-        else
-          {
-            gchar *text;
-
-            if (pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
-              {
-                g_value_set_string (value, text);
-                g_free (text);
-              }
-            else
-              g_value_set_string (value, NULL);
-          }
+       gchar *text = NULL;
+
+        if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
+          g_assert (NULL == text); /* text should still be NULL in case of markup errors */
+
+       g_value_set_string (value, text);
       }
       break;
     case PROP_TOOLTIP_MARKUP:
index 3a94c4438beb5a46bfad2e1e8cac27f0780a173b..358cb9065443ef772bc27b24d32da44e6161891e 100644 (file)
@@ -273,6 +273,8 @@ main (int argc, char *argv[])
   GtkTextIter iter;
   GtkTextTag *tag;
 
+  gchar *text, *markup;
+
   gtk_init (&argc, &argv);
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -289,6 +291,12 @@ main (int argc, char *argv[])
   gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
   gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 
+  text = gtk_widget_get_tooltip_text (button);
+  markup = gtk_widget_get_tooltip_markup (button);
+  g_assert (g_str_equal ("Hello, I am a static tooltip.", text));
+  g_assert (g_str_equal ("Hello, I am a static tooltip.", markup));
+  g_free (text); g_free (markup);
+
   /* A check button using the query-tooltip signal */
   button = gtk_check_button_new_with_label ("I use the query-tooltip signal");
   g_object_set (button, "has-tooltip", TRUE, NULL);
@@ -302,12 +310,24 @@ main (int argc, char *argv[])
   gtk_widget_set_tooltip_text (button, "Label & and tooltip");
   gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 
+  text = gtk_widget_get_tooltip_text (button);
+  markup = gtk_widget_get_tooltip_markup (button);
+  g_assert (g_str_equal ("Label & and tooltip", text));
+  g_assert (g_str_equal ("Label &amp; and tooltip", markup));
+  g_free (text); g_free (markup);
+
   /* A selectable label */
   button = gtk_label_new ("I am a selectable label");
   gtk_label_set_selectable (GTK_LABEL (button), TRUE);
   gtk_widget_set_tooltip_markup (button, "<b>Another</b> Label tooltip");
   gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 
+  text = gtk_widget_get_tooltip_text (button);
+  markup = gtk_widget_get_tooltip_markup (button);
+  g_assert (g_str_equal ("Another Label tooltip", text));
+  g_assert (g_str_equal ("<b>Another</b> Label tooltip", markup));
+  g_free (text); g_free (markup);
+
   /* Another one, with a custom tooltip window */
   button = gtk_check_button_new_with_label ("This one has a custom tooltip window!");
   gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);